package com.devicemantra.coordinate.ds.tests;
import com.devicemantra.coordinate.dataobjects.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.*;

import com.devicemantra.coordinate.dataobjects.CDepartmentFactory;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@SuppressWarnings("serial")
public class TestViewDepartment extends HttpServlet 
{
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException 
	{
		resp.setContentType("text/html");
		/* First let us populate a list of Department objects */
		List<CDepartment> lDeptList = CDepartmentFactory.getAllDepartments();
		for(int counter = 0; counter < lDeptList.size(); counter++)
		{
			CDepartment lDept = lDeptList.get(counter);
			resp.getOutputStream().println("Department name is " + lDept.getDepartmentName() + "<BR>");
			List<SubDepartment> lSubList = lDept.getSubDepartments();
			if( lSubList == null )
			{
				resp.getOutputStream().println("NO SUB DEPTS ");
			}
			else
			{
				for(int index = 0; index < lSubList.size(); index++)
				{
					resp.getOutputStream().println("SUB DEPARTMENT NAME [" + index + "] " + lSubList.get(index).getSubDepartmentName() + "<BR>");
					resp.getOutputStream().println("BELONGS TO ----> " + lSubList.get(index).getParentDepartment().getDepartmentName() + "<BR>");
				}
			}
			resp.getOutputStream().println("DESCRIPTION " + lDept.getDescription());
			resp.getOutputStream().println("DESIGNATION " + lDept.getContactInfo().getmDesignation());
			resp.getOutputStream().println("Mobile Number " + lDept.getContactInfo().getmContactNumber());
			resp.getOutputStream().println("Logo  " + lDept.getLogo().getName());
			resp.getOutputStream().println("<img src=getImage?" + "image_key=" + lDept.getLogo().getKey() + " />"); 
			resp.getOutputStream().println("DEPARTMENT ENDS HERE <BR>");
		}
		}
}

